<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>

    <title>通道信息修改</title>

	<meta http-equiv="pragma" content="no-cache">
	<meta http-equiv="cache-control" content="no-cache">
		<link rel="stylesheet" type="text/css" href="../ext/ext-all.css" />
		<script type="text/javascript" src="../ext/ext-base.js"></script>
		<script type="text/javascript" src="../ext/ext-all.js"></script>

	<style type="text/css">
	.ext-ie .x-menu-item-icon {left: -24px; top: 0px;}
	.ext-strict .x-menu-item-icon {left: 3px; top: 3px;}
	.ext-ie6 .x-menu-item-icon {left: -24px; top: 0px;}
	</style>
<script type="text/javascript">
Ext.BLANK_IMAGE_URL = '../images/s.gif';
</script>

	<script type="text/javascript">
	Ext.onReady(function(){
var thisgrid;
	//---定义修改form
	    var simple = new Ext.FormPanel({
	     region: 'east',
        labelWidth: 100, // label settings here cascade unless overridden
        url:'../ajaxjsp/channeleditor.jsp',
        frame:true,
        title: '通道信息修改',
        bodyStyle:'padding:5px 5px 0',
        width: '30%',
        defaults: {width: '100%'},
        defaultType: 'textfield',

        items: [{
                fieldLabel: '通道ID',
                name: 'hid',
               	xtype:'hidden',
               	id:'hid'
            },{
                fieldLabel: '通道自定义名',
                id :'hname',
                name: 'hname',
                allowBlank:false,
                blankText :'通道名必须填写'
            },{
                fieldLabel: '通道IP或服务地址',
                name: 'hip',
                labelWidth:150,
                vtypeText:'用户名只能包括字母或者数字'
            },{
                fieldLabel: '通道端口',
                name: 'hport',
                xtype:'numberfield'
            },
            {
                fieldLabel: '通道登录名',
                name: 'huname'
            },
            {
                fieldLabel: '密码',
                name: 'hpwd'
            },{
                fieldLabel: '余额少于多少提醒',
                name: 'hcondition'
            },

            {
                fieldLabel: '通道服务器名',
                name: 'hdefaultname'

            },{
                fieldLabel: '通道实现类',
                name: 'hclassname'
            },{
                fieldLabel: '备注',
                name: 'hnote'

            }

        ],

        buttons: [{
            text: '修改',
            handler : function(){simple.form.submit({
					waitMsg : '正在处理......',
					success : function(form, action) {
					    grid.store.reload();
						Ext.Msg.alert('成功',action.result.msg);
					},
					failure : function(form, action) {
						//form.reset();
						if (action.failureType == Ext.form.Action.SERVER_INVALID){
							Ext.MessageBox.alert('错误',action.result.errors.msg);
							}else{
							Ext.MessageBox.alert('错误','非法输入');
							}
					}
				});
            }
        },{
            text: '移除',
            handler : function(){
          		deleteProxy();
            }
        }]
    });
    //form end

	var AdminRecord = Ext.data.Record.create([
        {name: 'hid', type: 'string'},
        {name: 'hname', type: 'string'},
        {name: 'hip', type: 'string'},
        {name: 'hport', type: 'string'},
        {name: 'huname', type: 'string'},
        {name: 'hpwd', type: 'string'},
        {name: 'hclassname', type: 'string'},
        {name: 'hdefaultname', type: 'string'},
        {name: 'hnote', type: 'string'},
        {name: 'hcondition', type: 'string'}

    ]);

    var store = new Ext.data.Store({
        proxy: new Ext.data.HttpProxy({url: '../ajaxjsp/channellist.jsp'}),
        reader: new Ext.data.JsonReader({
        totalProperty: 'totalCount',
        root: 'result'
        },AdminRecord),
        remoteSort: true
    });


    var columns = new Ext.grid.ColumnModel([
        //{header: '编号', dataIndex: 'aid',width:1},
        new Ext.grid.RowNumberer(),
        {header: '通道服务器名', dataIndex: 'hdefaultname'},

        {header: '通道自定义名', dataIndex: 'hname'},
        {header: '通道IP或者服务地址', dataIndex: 'hip'},
        {header: '通道端口', dataIndex: 'hport'},
        {header: '通道用户名', dataIndex: 'huname'},
        {header: '通道密码', dataIndex: 'hpwd'},
        {header: '余额少于多少提醒', dataIndex: 'hcondition'},
        {header: '备注', dataIndex: 'hnote'}
    ]);

    columns.defaultSortable = true;
        var grid = new Ext.grid.GridPanel({
        title: '通道列表',
        region: 'center',
        loadMask: true,
        store: store,
        cm: columns,
        sm: new Ext.grid.RowSelectionModel({singleSelect:true}),
        viewConfig: {
        columnsText:'显示的列',
        sortAscText:'升序',
        sortDescText:'降序',
        forceFit: true
        },
        bbar: new Ext.PagingToolbar({
            pageSize: 15,
            store: store,
            displayInfo: true,
            displayMsg: '显示 {0} 条到 {1} 条记录，一共 {2} 条',
            emptyMsg:'没有记录'

        })
    });

    store.load({params:{start:0,limit:15}});
    grid.on('rowclick',function (grid,rowIndex,event){
    var record = grid.getStore().getAt(rowIndex);
   	simple.getForm().loadRecord(record);
    });


	var viewport = new Ext.Viewport({
	renderTo:'mt',
	layout:'border',
	items:[
	grid,simple,
	{region:'south',contentEl:'inp',heigth:40}
	//{region:'east',html:'east',width:'30%'}
	]
	});

	thisgrid =grid;

	function deleteProxy(){
			var hidvalue = Ext.getCmp('hid').getValue();
                 if(hidvalue == ''){
                 	Ext.Msg.alert('警告','你未选择任何通道！');
                 	return;
                 }
                 if('aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa' == hidvalue){
                 Ext.Msg.alert('警告','占位空通道不允许删除');
                 	return;
                 }

                 var uvalue = Ext.getCmp('hname').getValue();
	   			Ext.MessageBox.confirm('警告', '你确定要删除通道【'+uvalue+'】吗？<br>1、若已经给代理配置了该通道，那么将移除该代理使用该通道权利。<br>2、已经使用该通道的用户所发送的短信将发送失败。', function(btn){
                if (btn == 'yes') {
                 Ext.Ajax.request({
                  url : '../ajaxjsp/delete.jsp',
                  method : 'POST',
                  params : {
                      tablename : 'sms_channel',
                      id :hidvalue
                  },

                 success: function(response, options) {
                        //获取响应的json字符串
                       var responseArray = Ext.util.JSON.decode(response.responseText);
                            if(responseArray.success==true){
								//Ext.Msg.alert('成功',responseArray.msg);
								simple.form.reset();
								grid.store.reload();
                            }
                            else{
                                Ext.Msg.alert('失败',responseArray.msg);
                            }
                         }
              });
                }
            });
	}



});
	</script>
  </head>

  <body>
   <div id="mt"></div>
   <div id="north1"></div>
   <div id="south"></div>
    <div id="wait" align="center"></div>
   <input id="inp" value="刷新页面" type="button" onclick="javascript:window.location.reload();"></input>
  </body>
</html>
